#include "hardtool.h"
#include "../CheckInfor/hardinfor.h"
#include <iostream>
using Yzty::HardTool;

HardTool* HardTool::_instance=nullptr;


QString HardTool::cpucommand="sudo cat /proc/cpuinfo";
QString HardTool::bioscommand="sudo dmidecode -t 0";
QString HardTool::mesoltcommand="sudo dmidecode -t memory";
QString HardTool::mobocommand="sudo dmidecode -t 2";
QString HardTool::memorycommand="sudo dmidecode -t 17";
QString HardTool::graphcardcommand="sudo lshw -c display";
QString HardTool::graphcardcommand_2="sudo hwinfo --display";
QString HardTool::graphreslutioncommand="sudo xrandr --current";
QString HardTool::networkcommand="sudo lshw -c network";
QString HardTool::mousecommand="sudo hwinfo --mouse";
QString HardTool::keyboardcommand="sudo hwinfo --keyboard";
QString HardTool::batterycommand="sudo upower -i /org/freedesktop/UPower/devices/battery_BAT0";
QString HardTool::soundcommand="sudo lshw -c sound";
QString HardTool::diskcommand="sudo hwinfo --disk";
QString HardTool::diskmediumcommand="sudo cat /sys/block/%1/queue/rotational";
QString HardTool::bluetoothcommand="sudo hwinfo --bluetooth";
QString HardTool::oscommand="sudo dmidecode -t 1";
QString HardTool::listuser="sudo ls /home/";
QString HardTool::stateuser="sudo w %1 -h -f";
QString HardTool::loginuser="sudo last %1 -n 20";
QString HardTool::userinfocommand="w -h";
QString HardTool::userrebootcommand="last|grep reboot";

HardTool* HardTool::GetInstance()
{
    if(HardTool::_instance==nullptr)
        HardTool::_instance=new HardTool();
    return HardTool::_instance;
}

HardTool::HardTool()
{
    QStringList temp=QSysInfo::buildAbi().split('-');
    this->_cpuarch=temp[0];
    this->_end=temp[1];
    this->_wordsize=temp[2];
}

HardTool::~HardTool()
{

}

std::function<void()> HardTool::getToolFunction(HardToolCode index)
{
    /*函数打包向线程池投递
     * index:功能索引
    */
    std::function<void()> func;
    switch (index)
    {
        case HardToolCode::Cpu:
            func=[this]()
            {
                std::vector<cpuInfor>&& infors=GetCpuInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::Cpu,infors);
            };
            break;
        case HardToolCode::MotherBoard:
            func=[this]()
            {
                std::vector<moboInfor>&& infors=GetMoboInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::MotherBoard,infors);
            };
            break;
         case HardToolCode::Memory:
            func=[this]()
            {
                std::vector<memoryInfor>&& infors=GetMemoryInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::Memory,infors);
            };
            break;
        case HardToolCode::GraphCard:
            func=[this]()
            {
                std::vector<graphcardInfor>&& infors=GetGraphCardInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::GraphCard,infors);
            };
            break;
        case HardToolCode::SoundCard:
            func=[this]()
            {
                std::vector<soundcardInfor>&& infors=GetSoundInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::SoundCard,infors);
            };
            break;
        case HardToolCode::HardDisk:
            func=[this]()
            {
                std::vector<diskInfor>&& infors=GetdiskInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::HardDisk,infors);
            };
            break;
        case HardToolCode::Battery:
            func=[this]()
            {
                std::vector<batteryInfor>&& infors=GetBatteyInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::Battery,infors);
            };
            break;
        case HardToolCode::BlueTooth:
            func=[this]()
            {
                std::vector<bluetoothInfor>&& infors=GetbluetoothInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::BlueTooth,infors);
            };
            break;
        case HardToolCode::NetCard:
            func=[this]()
            {
                std::vector<networkcardInfor>&& infors=GetNetWorkInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::NetCard,infors);
            };
            break;
        case HardToolCode::Mouse:
            func=[this]()
            {
                std::vector<mouseInfor>&& infors=GetMouseInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::Mouse,infors);
            };
            break;
        case HardToolCode::KeyBoard:
            func=[this]()
            {
                std::vector<keyboardInfor>&& infors=GetKeyBoardInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::KeyBoard,infors);
            };
            break;
        case HardToolCode::OsAndHost:
            func=[this]()
            {
                std::vector<osInfor> infors=GetosInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::OsAndHost,infors);
            };
            break;
        case HardToolCode::User:
            func=[this]()
            {
                std::vector<userInfor> infors=GetUserInfor();
                HardInfor::GetInstance()->SetNormalCheck(HardToolCode::User,infors);
            };
            break;
        default:
            break;
    }
    return func;
}

std::vector<Yzty::cpuInfor> HardTool::GetCpuInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::cpucommand,items);
    std::vector<cpuInfor> infors;
    for(int i=1;i<=items;++i)
    {
        cpuInfor infor(static_cast<uint16_t>(HardToolCode::Cpu));
        QString tie;
        if(i!=1)
            tie=QString::number(i);
        infor._prodname=cmdinfors[cpuInfor::ProductName+tie];
        infor._vendorname=cmdinfors[cpuInfor::Vendor+tie];
        infor._model=cmdinfors[cpuInfor::Model+tie];
        infor._fmhz=cmdinfors[cpuInfor::CpuMHz+tie];
        infor._mips=cmdinfors[cpuInfor::BogoMips+tie];
        infor._coreid=cmdinfors[cpuInfor::CoreId+tie];
        infor._cores=cmdinfors[cpuInfor::Cores+tie];
        infor._procid=cmdinfors[cpuInfor::processor+tie];
        infor._arch=this->_cpuarch;
        infor._end=this->_end;
        infor._wordsize=this->_wordsize;

        infors.push_back(std::move(infor));
    }
    return infors;
}

std::vector<Yzty::biosInfor> HardTool::GetBiosInfor()
{
    biosInfor infor;
    std::vector<Yzty::biosInfor> infors;

    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::bioscommand,items);

    infor._vendorname.operator=(cmdinfors[biosInfor::Vendor]);
    infor._version.operator=(cmdinfors[biosInfor::Version]);
    infor._runmemor=cmdinfors[biosInfor::RuntimeSize];
    infor._rom=cmdinfors[biosInfor::ROMSize];
    infor._feature.operator=(std::move(cmdinfors[biosInfor::Features]));

    infors.push_back(std::move(infor));
    return infors;
}

std::vector<Yzty::mesoltInfor> HardTool::GetMesoltInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::mesoltcommand,items);

    //将信息写入结构体
    mesoltInfor infor;
    infor._pos.operator=(std::move(cmdinfors[mesoltInfor::Postion]));
    infor._mgb=cmdinfors[mesoltInfor::MaxCapacity];
    infor._solts=cmdinfors[mesoltInfor::NumDevice];

    //信息打包丢出
    std::vector<Yzty::mesoltInfor> infors;
    infors.push_back(std::move(infor));
    return infors;
}

std::vector<Yzty::moboInfor> HardTool::GetMoboInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::mobocommand,items);
    moboInfor infor(static_cast<uint16_t>(HardToolCode::MotherBoard));
    std::vector<Yzty::moboInfor> infors;

    std::vector<biosInfor>&& biosinfors=this->GetBiosInfor();
    std::vector<mesoltInfor>&& soltinfors=this->GetMesoltInfor();

    for(int i=1;i<=items;++i)
    {
        QString tie="";
        if(i>1)
            tie=QString::number(i);
        infor._prodname=(std::move(cmdinfors[moboInfor::ProductName+tie]));
        infor._vendorame=(std::move(cmdinfors[moboInfor::Vendor+tie]));
        infor._version.operator=(std::move(cmdinfors[moboInfor::Version+tie]));
        infor._serialnum.operator=(std::move(cmdinfors[moboInfor::SerialNumber+tie]));
        infor._model.operator=(std::move(cmdinfors[moboInfor::Type+tie]));
        infor._feature.operator=(std::move(cmdinfors[moboInfor::Feature+tie]));
        infor._bios=std::move(biosinfors[0]);
        infor._msolts=std::move(soltinfors[0]);
        infors.push_back(infor);
    }

    return infors;
}

std::vector<Yzty::memoryInfor> HardTool::GetMemoryInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::memorycommand,items);

    std::vector<memoryInfor> infors;
    memoryInfor infor(static_cast<uint16_t>(HardToolCode::Memory));
    for(int i=1;i<=items;++i)
    {
        QString tie;
        if(i>1)
            tie=QString::number(i);
        infor._prodname=std::move(cmdinfors[memoryInfor::ProductName+tie]);
        infor._vendorname=std::move(cmdinfors[memoryInfor::Vendor+tie]);
        infor._model=std::move(cmdinfors[memoryInfor::Type+tie]);
        infor._slottype=std::move(cmdinfors[memoryInfor::SoltType+tie]);
        infor._serialnum=std::move(cmdinfors[memoryInfor::SerialNumber+tie]);
        infor._mgb=std::move(cmdinfors[memoryInfor::MemorySize+tie]);
        infor._mhz=std::move(cmdinfors[memoryInfor::Mhz+tie]);
        infor._dataw=std::move(cmdinfors[memoryInfor::DataWidth+tie]);
        infor._speed=std::move(cmdinfors[memoryInfor::Speed+tie]);

        infors.push_back(std::move(infor));
    }
    return infors;
}

std::vector<Yzty::graphcardInfor> HardTool::GetGraphCardInfor()
{
    FILE* fp=popen("xrandr --current","r");
    QTextStream fstream(fp);
    QStringList reslutionInfor=fstream.readLine().split(':')[1].split(',');

    for(int i=0;i<reslutionInfor.size();++i)
    {
        QStringList temp=reslutionInfor[i].simplified().split(' ');
        reslutionInfor[i]=temp[1]+temp[2]+temp[3];
    }

    int items=0,items_2=0;
    QMap<QString,QString>&& cmdinfors_1=SerializaShellInput(graphcardcommand,items);
    QMap<QString,QString>&& cmdinfors_2=SerializaShellInput(graphcardcommand_2,items_2);
    std::vector<graphcardInfor> infors;
    graphcardInfor infor(static_cast<uint16_t>(HardToolCode::GraphCard));



    for(int i=1;i<=items;++i)
    {
        QString tie;
        if(i>1)
            tie=QString::number(i);

        infor._prodname=std::move(cmdinfors_1[graphcardInfor::ProductName+tie]);
        infor._vendorname=std::move(cmdinfors_1[graphcardInfor::Vendor+tie]);
        infor._description=std::move(cmdinfors_1[graphcardInfor::Descript+tie]);
        infor._version=std::move(cmdinfors_1[graphcardInfor::Version+tie]);
        infor._ability=std::move(cmdinfors_1[graphcardInfor::Ability+tie]);
        infor._dataw=std::move(cmdinfors_1[graphcardInfor::DataWidth+tie]);
        infor._mhz=std::move(cmdinfors_1[graphcardInfor::MHz+tie]);

        infor._interface=std::move(cmdinfors_2[graphcardInfor::Interface+tie]);
        infor._driver=std::move(cmdinfors_2[graphcardInfor::Drive+tie]);
        infor._config=std::move(cmdinfors_2[graphcardInfor::Config+tie]);
        infor._ioport=std::move(cmdinfors_2[graphcardInfor::IoPort+tie]);
        infor._model=std::move(cmdinfors_2[graphcardInfor::Model+tie]);

        infor._curslt=reslutionInfor[1];
        infor._minslt=reslutionInfor[0];
        infor._maxslt=reslutionInfor[2];

        infors.push_back(std::move(infor));
    }
    return infors;
}

std::vector<Yzty::networkcardInfor> HardTool::GetNetWorkInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::networkcommand,items);

    std::vector<networkcardInfor> infors;
    networkcardInfor infor(static_cast<uint16_t>(HardToolCode::NetCard));

    for(int i=1;i<=items;++i)
    {
        QString tie;
        if(i>1)
            tie=QString::number(i);

        infor._prodname=cmdinfors[networkcardInfor::ProductName+tie];
        infor._vendorbname=cmdinfors[networkcardInfor::Vendor+tie];
        infor._model=cmdinfors[networkcardInfor::Type+tie];
        infor._version=cmdinfors[networkcardInfor::Version+tie];
        infor._ability=cmdinfors[networkcardInfor::Ability+tie];
        infor._config=cmdinfors[networkcardInfor::Config+tie];
        infor._dataw=cmdinfors[networkcardInfor::DataWidth+tie];
        infor._resource=cmdinfors[networkcardInfor::Resource+tie];
        infor._mhz=std::move(cmdinfors[networkcardInfor::Mhz+tie]);
        infor._Serial = std::move(cmdinfors[networkcardInfor::Serial+tie]);
        infor._logicalname = std::move(cmdinfors[networkcardInfor::logicalname+tie]);

        infors.push_back(std::move(infor));
    }
    return infors;
}

std::vector<Yzty::mouseInfor> HardTool::GetMouseInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(mousecommand,items);

    std::vector<mouseInfor> infors;
    mouseInfor infor(static_cast<uint16_t>(HardToolCode::Mouse));

    for(int i=1;i<=items;++i)
    {
        QString tie;
        if(i>1)
            tie=QString::number(i);

        infor._probname=std::move(cmdinfors[mouseInfor::ProductName+tie]);
        infor._vendorname=std::move(cmdinfors[mouseInfor::Vendor+tie]);
        infor._model=std::move(cmdinfors[mouseInfor::Type+tie]);
        infor._interface=cmdinfors.count(mouseInfor::Interface+tie)?cmdinfors[mouseInfor::Interface+tie]:"PS/2";
        infor._hwclass=std::move(cmdinfors[mouseInfor::Hwclass+tie]);
        infor._config=std::move(cmdinfors[mouseInfor::Config+tie]);

        infors.push_back(infor);
    }
    return infors;
}

std::vector<Yzty::keyboardInfor> HardTool::GetKeyBoardInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(keyboardcommand,items);

    std::vector<keyboardInfor> infors;
    keyboardInfor infor(static_cast<uint16_t>(HardToolCode::KeyBoard));

    for(int i=1;i<=items;++i)
    {
        QString tie;
        if(i>1)
            tie=QString::number(i);

        infor._probname=std::move(cmdinfors[keyboardInfor::ProductName+tie]);
        infor._vendorname=std::move(cmdinfors[keyboardInfor::Vendor+tie]);
        infor._model=std::move(cmdinfors[keyboardInfor::Type+tie]);
        infor._interface=cmdinfors.count(keyboardInfor::Interface+tie)?cmdinfors[keyboardInfor::Interface+tie]:"PS/2";
        infor._hwclass=std::move(cmdinfors[keyboardInfor::Hwclass+tie]);
        infor._config=std::move(cmdinfors[keyboardInfor::Config+tie]);

        infors.push_back(std::move(infor));
    }
    return infors;
}

std::vector<Yzty::batteryInfor> HardTool::GetBatteyInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::batterycommand,items);

    std::vector<batteryInfor> infors;
    batteryInfor infor(static_cast<uint16_t>(HardToolCode::Battery));

    for(int i=1;i<=items;++i)
    {
        QString tie;
        if(i>1)
            tie=QString::number(i);

        infor._probname=std::move(cmdinfors[batteryInfor::ProductName+tie]);
        infor._vendorname=std::move(cmdinfors[batteryInfor::Vendor+tie]);
        //infor._version=std::move(cmdinfors[batteryInfor::Version+tie]);
        infor._serialnum=std::move(cmdinfors[batteryInfor::SerialNum+tie]);
        infor._updatedtime=std::move(cmdinfors[batteryInfor::UpdateTime+tie]);
        infor._state=std::move(cmdinfors[batteryInfor::State+tie]);
        infor._cur_energy=cmdinfors[batteryInfor::Energy+tie];
        infor._energy_full=cmdinfors[batteryInfor::FullEnergy+tie];
        infor._energy_full_desgin=cmdinfors[batteryInfor::DesihmFullEnergy+tie];
        infor._energy_rate=cmdinfors[batteryInfor::RateEnergy+tie];
        infor._voltage=cmdinfors[batteryInfor::Volatage+tie];
        infor._percentage=cmdinfors[batteryInfor::Percentage+tie];
        infor._capacity=cmdinfors[batteryInfor::Capacity+tie];

        infors.push_back(std::move(infor));
    }
    return infors;
}

std::vector<Yzty::soundcardInfor> HardTool::GetSoundInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::soundcommand,items);

    std::vector<soundcardInfor> infors;
    soundcardInfor infor(static_cast<uint16_t>(HardToolCode::SoundCard));

    for(int i=1;i<=items;++i)
    {
        QString tie;
        if(i>1)
            tie=QString::number(i);

        infor._probname=std::move(cmdinfors[soundcardInfor::ProductName+tie]);
        infor._vendorname=std::move(cmdinfors[soundcardInfor::Vendor+tie]);
        infor._version=std::move(cmdinfors[soundcardInfor::Version+tie]);
        infor._model=std::move(cmdinfors[soundcardInfor::Type+tie]);
        infor._ability=std::move(cmdinfors[soundcardInfor::Ability+tie]);
        infor._config=std::move(cmdinfors[soundcardInfor::Config+tie]);
        infor._mhz=std::move(cmdinfors[soundcardInfor::Mhz+tie]);
        infor._dataw=std::move(cmdinfors[soundcardInfor::DataWidth+tie]);

        infors.push_back(std::move(infor));
    }
    return infors;
}

std::vector<Yzty::diskInfor> HardTool::GetdiskInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::diskcommand,items);

    std::vector<diskInfor> infors;
    diskInfor infor(static_cast<uint16_t>(HardToolCode::HardDisk));

    for(int i=1;i<=items;++i)
    {
        QString tie;
        if(i>1)
            tie=QString::number(i);

        infor._prodname=std::move(cmdinfors[diskInfor::ProductName+tie]);
        infor._vendorname=std::move(cmdinfors[diskInfor::Vendor+tie]);
        infor._interface=std::move(cmdinfors[diskInfor::Interface+tie]);
//        infor._serialnum=std::move(cmdinfors[diskInfor::Hwclass+tie]);
        infor._devicefiles=std::move(cmdinfors[diskInfor::DeviceFile+tie]);
        infor._config=std::move(cmdinfors[diskInfor::Config+tie]);
        infor._hwclass=std::move(cmdinfors[diskInfor::Hwclass+tie]);
        infor._mgb=std::move(cmdinfors[diskInfor::Size+tie]);
        infor._driver=std::move(cmdinfors[diskInfor::Driver+tie]);
        //读取序列号
        QString cmd = QString("lsblk --nodeps -no serial %1").arg(infor._devicefiles);
        FILE *fp1=popen(cmd.toLocal8Bit(),"r");
        if(fp1!=nullptr) {
            QTextStream stream(fp1);
            infor._serialnum = stream.readAll().simplified();
        }
        fclose(fp1);

        //读取介质类型
        FILE* fp=popen(HardTool::diskmediumcommand.arg(infor._devicefiles.split('/').back()).toStdString().c_str(),"r");
        if(fp==nullptr)
            throw "[ERROR] disk medium";
        int ch=getc(fp);
        infor._medium=ch=='0'?"SSD":"HHD";
        fclose(fp);

        infors.push_back(std::move(infor));
    }
    return infors;
}

std::vector<Yzty::bluetoothInfor> HardTool::GetbluetoothInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::bluetoothcommand,items);

    std::vector<bluetoothInfor> infors;
    bluetoothInfor infor(static_cast<uint16_t>(HardToolCode::BlueTooth));

    for(int i=1;i<=items;++i)
    {
        QString tie;
        if(i>1)
            tie=QString::number(i);

        infor._prodname=std::move(cmdinfors[bluetoothInfor::ProductName+tie]);
        infor._vendorname=std::move(cmdinfors[bluetoothInfor::Vendor+tie]);
        infor._driver=std::move(cmdinfors[bluetoothInfor::Driver+tie]);
        infor._config=std::move(cmdinfors[bluetoothInfor::Config+tie]);
        infor._spped=std::move(cmdinfors[bluetoothInfor::Speed+tie]);
        infor._hwclass=std::move(cmdinfors[bluetoothInfor::Hwclass+tie]);
        infor._interface=std::move(cmdinfors[bluetoothInfor::Interface+tie]);

        infors.push_back(std::move(infor));
    }
    return infors;
}

std::vector<Yzty::osInfor> HardTool::GetosInfor()
{
    int items=0;
    QMap<QString,QString>&& cmdinfors=SerializaShellInput(HardTool::oscommand,items);
    std::vector<osInfor> infors;
    osInfor infor(static_cast<uint16_t>(HardToolCode::OsAndHost));

    infor._machinename=std::move(cmdinfors[osInfor::Machinename]);
    infor._UUID=std::move(cmdinfors[osInfor::UUID]);
    infor._vendor=std::move(cmdinfors[osInfor::Vendor]);

    infor._osname=QSysInfo::prettyProductName();
    infor._ostype=QSysInfo::productType();
    infor._osversion=QSysInfo::productVersion();
    infor._kerneltype=QSysInfo::kernelType();
    infor._kernelversion=QSysInfo::kernelVersion();
    infor._cpuinfor=QSysInfo::buildAbi();

    infors.push_back(std::move(infor));
    return infors;
}

/*
std::vector<Yzty::userInfor> HardTool::GetUserInfor()
{
    userInfor infor(static_cast<uint16_t>(HardToolCode::User));
    std::vector<userInfor> infors;
    FILE* fp=popen(userinfocommand.toStdString().c_str(),"r");
    FILE* fp1=popen(userrebootcommand.toStdString().c_str(),"r");
    if(fp==nullptr || fp1==nullptr)
    {
        std::cerr<<"[ERROR] exculte "<<userinfocommand.toStdString()<<std::endl;
        throw userinfocommand+"=error";
    }
    QTextStream fstream(fp);
    QTextStream fstream1(fp1);
    QString rebootstr=fstream1.readAll();
    fclose(fp1);
    while(!fstream.atEnd())
    {
        QStringList temp=fstream.readLine().simplified().split(' ');
        infor._username=temp[0];
        infor._tty=temp[1];
        infor._logtime=temp[3];
        infor._pcpu=temp[6];
        infor._what=temp[7];

        if(!infors.size())
            infor._log.push_back(rebootstr);
        else
            infor._log.push_back(" ");

        infors.push_back(infor);

    }
    fclose(fp);
    return infors;
}*/

std::vector<Yzty::userInfor> HardTool::GetUserInfor()
{
    auto func=[](const QString& command)->QString{
        FILE* fp=popen(command.toStdString().c_str(),"r");
        QTextStream fstream(fp);
        QString temp=fstream.readAll();
        fclose(fp);
        return temp;
    };
    std::vector<userInfor> infors;
    userInfor infor(static_cast<uint16_t>(HardToolCode::User));

    QStringList userlist=func(HardTool::userinfocommand).simplified().split(' ');


    int s=userlist.size();
    QString tmp=func(HardTool::userrebootcommand);

            infor._username=std::move(userlist[0]);
            infor._tty=std::move(userlist[1]);
            infor._logtime=std::move(userlist[s-3]);
            infor._pcpu=std::move(userlist[s-2]);
            infor._what=std::move(userlist[s-1]);

            if(!infors.size())
                infor._log.push_back(tmp);
            else
                infor._log.push_back(" ");

        infors.push_back(std::move(infor));

    return infors;
}
/*
std::vector<Yzty::userInfor> HardTool::GetUserInfor()
{
    auto func=[](const QString& command)->QStringList{
        FILE* fp=popen(command.toStdString().c_str(),"r");
        QTextStream fstream(fp);
        QStringList temp=fstream.readAll().split('\n');
        fclose(fp);
        return temp;
    };

    std::vector<userInfor> infors;
    userInfor infor(static_cast<uint16_t>(HardToolCode::User));

    QStringList userlist=func(HardTool::listuser)[0].simplified().split(' ');

    for(QString& user:userlist)
    {
        QStringList stateul=func(HardTool::stateuser.arg(user))[0].simplified().split(' ');
        if(stateul.size()==7)
        {
            infor._username=std::move(user);
            infor._tty=std::move(stateul[userInfor::Tty]);
            infor._logtime=std::move(stateul[userInfor::Logtime]);
            infor._pcpu=std::move(stateul[userInfor::Pcpu]);
            infor._what=std::move(stateul[userInfor::What]);
        }
        infor._log=func(HardTool::loginuser.arg(user));
        infors.push_back(std::move(infor));
    }
    return infors;
}
*/
